<?php
/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * Administration Control Panel Script (Backend)
 * Started: September 26, 2009 8:31 PM
 * Script version: 1.0
 */

session_start(); # FIXME: Shouldn't put this here?

// Initialize CBB
define("APP_TYPE", "backend");

require_once(dirname(__FILE__)."/core/initialize.php");

// Modular System
if(isset($_GET["app"])){
	if(isset($_SESSION["cf_admin_username"])){
		if(isset($_SESSION["cf_controller"])){ # Yep should
			$userController = unserialize($_SESSION["cf_controller"]);
			if($userController->group->is_admin()){
				define("APPLICATION", $_GET["app"]);
			}
			else{
				unset($_SESSION["cf_admin_username"]);
				define("APPLICATION", "login");
				if(!isset($_POST['username'], $_POST['password'])){
					define("MODULE", "form");
				}
			}
		}
	}
	else{
		define("APPLICATION", "login");
		if(!isset($_POST['username'], $_POST['password'])){
			define("MODULE", "form");
		}
	}
}
else{
	if(isset($_SESSION["cf_admin_username"])){
		define("APPLICATION", "home");
	}
	else{
		define("APPLICATION", "login");
		if(!isset($_POST['username'], $_POST['password'])){
			define("MODULE", "form");
		}
	}
}
require_once(CORE_PATH."app/application.php");
$app = new application_system(APP_TYPE, APPLICATION);
if(!defined("MODULE")){
	if(!isset($_GET["module"])){
		define("MODULE", $app->getDefaultModule());
	}
	else{
		define("MODULE", $_GET["module"]);
	}
}

//////////////////////////////////
// Initialize the Modular System
require_once(CORE_PATH."app/module.php");
$module = new modular_system(APP_TYPE, APPLICATION, MODULE);
$view->initHeader($module->getModuleTitle());
$view->footer();
$view->output();
// bah.
